package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseSystem;
import com.ruoyi.base.service.IBaseSystemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 子系统类型Controller
 * 
 * @author yepanpan
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/base/system")
public class BaseSystemController extends BaseController
{
    @Autowired
    private IBaseSystemService baseSystemService;

    /**
     * 查询子系统类型列表
     */
    @GetMapping("/select")
    public TableDataInfo select(BaseSystem baseSystem)
    {
        List<BaseSystem> list = baseSystemService.selectBaseSystemList(baseSystem);
        return getDataTable(list);
    }

    /**
     * 查询子系统类型列表
     */
    @PreAuthorize("@ss.hasPermi('base:system:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseSystem baseSystem)
    {
        startPage();
        List<BaseSystem> list = baseSystemService.selectBaseSystemList(baseSystem);
        return getDataTable(list);
    }

    /**
     * 导出子系统类型列表
     */
    @PreAuthorize("@ss.hasPermi('base:system:export')")
    @Log(title = "子系统类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseSystem baseSystem)
    {
        List<BaseSystem> list = baseSystemService.selectBaseSystemList(baseSystem);
        ExcelUtil<BaseSystem> util = new ExcelUtil<BaseSystem>(BaseSystem.class);
        util.exportExcel(response, list, "子系统类型数据");
    }


    /**
     * 获取子系统类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:system:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseSystemService.selectBaseSystemById(id));
    }

    /**
     * 新增子系统类型
     */
    @PreAuthorize("@ss.hasPermi('base:system:add')")
    @Log(title = "子系统类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BaseSystem baseSystem)
    {
        return toAjax(baseSystemService.insertBaseSystem(baseSystem));
    }

    /**
     * 修改子系统类型
     */
    @PreAuthorize("@ss.hasPermi('base:system:edit')")
    @Log(title = "子系统类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BaseSystem baseSystem)
    {
        return toAjax(baseSystemService.updateBaseSystem(baseSystem));
    }

    /**
     * 删除子系统类型
     */
    @PreAuthorize("@ss.hasPermi('base:system:remove')")
    @Log(title = "子系统类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseSystemService.deleteBaseSystemByIds(ids));
    }
}
